# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器，以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。

# 根据将生成或运行容器的主机的操作系统，可能需要更改 FROM 语句中指定的映像。
# 有关详细信息，请参阅 https://aka.ms/containercompat

# 基于 Windows 容器（Nano Server）的运行时镜像
FROM mcr.microsoft.com/dotnet/aspnet:9.0-nanoserver-1809 AS base
WORKDIR /app

# 设置 HTTP 和 HTTPS 端口
ENV ASPNETCORE_HTTP_PORT=4999

# 其他设置
EXPOSE 4999

# 基于 SDK 镜像进行构建
FROM mcr.microsoft.com/dotnet/sdk:9.0-nanoserver-1809 AS build


ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["DemoWebapi01.csproj", "."]
RUN dotnet restore "./DemoWebapi01.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./DemoWebapi01.csproj" -c $BUILD_CONFIGURATION -o /app/build

# 发布阶段
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./DemoWebapi01.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# 生产阶段
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DemoWebapi01.dll"]
